package org.zoomdev.zoom.web.parameter;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.lang.reflect.Type;

public final class ParameterParserFactory {

    private final ParameterAdapterFactoryManager manager;

    public ParameterParserFactory(ParameterAdapterFactoryManager manager) {
        this.manager = manager;
    }


    public ParameterParser createParameterParser(Method method, String[] names) {
        int c = names.length;
        Type[] genericTypes = method.getGenericParameterTypes();
        ParameterAdapter[] adapters = new ParameterAdapter[c];
        Parameter[] parameters = method.getParameters();
        for (int i = 0; i < c; ++i) {
            adapters[i] = manager.createParameterAdapter(names[i], genericTypes[i], parameters[i]);
        }
        return new ParameterParser(names, genericTypes, adapters);
    }
}
